{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "35c692e9",
   "metadata": {},
   "source": [
    "## 1. 优化百度ASR接口"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a3a81473",
   "metadata": {},
   "outputs": [],
   "source": [
    "from bdasr import fetch_token,asr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8a55e024",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 以下为asr代码的优化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "daf1397d",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "API_KEY = 'rcErguEr2A8azm27GhPkUmcs'\n",
    "SECRET_KEY = 'BRu3ntTRbjSG45wOujDljwainuzgNoPu'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "04ef742d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.4ed0d5e8fe20c111e7dd6fe7e471a5d5.2592000.1655804861.282335-26192293'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 给使用者使用\n",
    "li_token = fetch_token(API_KEY,SECRET_KEY)\n",
    "li_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "28c85821",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 准备音频文件\n",
    "import speech_recognition\n",
    "r = speech_recognition.Recognizer()\n",
    "with speech_recognition.Microphone() as source:\n",
    "    audio = r.listen(source)\n",
    "# 将数据保存到wav文件中\n",
    "with open(\"1.wav\", \"wb\") as f: \n",
    "    f.write(audio.get_wav_data(convert_rate=16000))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "51d79d51",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"corpus_no\":\"7100486964963067485\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"你不知道吗？\"],\"sn\":\"815317158591653210950\"}\\n'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "asr(token = li_token, AUDIO_FILE = '1.wav')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "de7443f6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
